package com.ld.security.common.mybatis.base.vo;


import com.ld.security.common.mybatis.util.GroupColumn;
import com.ld.security.common.mybatis.util.TableUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Data
public class PageGroupVo<E> extends PageVo<E> {


	@ApiModelProperty("聚合结果集")
	private Map<String,List<GroupColumn> > groupMap = new HashMap<>();




	/**
	 * 聚合行
	 * @param fieldNames
	 * @return
	 */
	public PageGroupVo<E> groupRows(List<String> fieldNames){
		List<E> list =  this.getList();
		List<String> ks =  new LinkedList<>();
		for (String fieldName : fieldNames) {
			//
			ks.add(fieldName);
			List<GroupColumn> columns = TableUtil.groupRows(list,ks);
			groupMap.put(fieldName,columns);
		}

		return this;

	}



}
